package ThreadPoolnio1;

import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class TCPClient2 {
    public static void main(String[] args) throws IOException {

    }
    public  static  void  client(String ip , int port , JTextComponent txtSend) throws IOException {
       Socket s = null;
       try{
           s = new Socket(ip , port);
           Scanner in = new Scanner(System.in);
           String msg = null;
           PrintWriter out = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "GBK"));
           while (true){
               if((msg =txtSend.getText())!= null){
                   out.println(msg);
                   out.flush();
                   if(msg.equals("q")) break;
               }
           }
       } catch (UnknownHostException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
       finally {
           if(s != null){
               s.close();
           }
       }
    }
}